/*------------------------------------------------------------------------------
$module:      InstantProp
$package:     CseApi
$purpose:     Define TInt/TWint/TFloat/TString instant property access
$author:      Wayne Chan
$CreateAt:    10/03/25
$LastModify:
$license:     Mozilla Public License Version 1.1
------------------------------------------------------------------------------*/

#include "CseApi_.h"

// class TIntProp
//------------------------------------------------------------------------------
TIntProp::TIntProp()
{
    value = 0;
    m_owner = NULL;
    m_callback = NULL;
}

TIntProp::~TIntProp()
{
}

void TIntProp::bindMethod(void *owner, void *AccessFunc)
{
    m_owner = owner;
    m_callback = (TInt (*)(void *,TIntObj&,TInt *)) AccessFunc;
}

TIntProp& TIntProp::operator=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
        m_callback(m_owner,value,&i);
    else value = i;
    return *this;
}

TIntProp::operator TInt() const
{
    if (m_owner != NULL && m_callback != NULL)
        return m_callback(m_owner,(TIntObj&)value,NULL);
    else return value;
}

TIntProp& TIntProp::operator++()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TInt i = value + 1;
        m_callback(m_owner,value,&i);
    }
    else ++value;
    return *this;
}

TIntProp& TIntProp::operator++(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TInt i = value + 1;
        m_callback(m_owner,value,&i);
    }
    else value++;
    return *this;
}

TIntProp& TIntProp::operator--()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TInt i = value - 1;
        m_callback(m_owner,value,&i);
    }
    else --value;
    return *this;
}

TIntProp& TIntProp::operator--(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TInt i = value - 1;
        m_callback(m_owner,value,&i);
    }
    else value--;
    return *this;
}

void TIntProp::operator*=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value * i;
        m_callback(m_owner,value,&i);
    }
    else value *= i;
}

void TIntProp::operator/=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value / i;
        m_callback(m_owner,value,&i);
    }
    else value /= i;
}

void TIntProp::operator%=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value % i;
        m_callback(m_owner,value,&i);
    }
    else value %= i;
}

void TIntProp::operator+=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value + i;
        m_callback(m_owner,value,&i);
    }
    else value += i;
}

void TIntProp::operator-=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value - i;
        m_callback(m_owner,value,&i);
    }
    else value -= i;
}

void TIntProp::operator<<=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value << i;
        m_callback(m_owner,value,&i);
    }
    else value <<= i;
}

void TIntProp::operator>>=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value >> i;
        m_callback(m_owner,value,&i);
    }
    else value >>= i;
}

void TIntProp::operator&=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value & i;
        m_callback(m_owner,value,&i);
    }
    else value &= i;
}

void TIntProp::operator|=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value | i;
        m_callback(m_owner,value,&i);
    }
    else value |= i;
}

void TIntProp::operator^=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value ^ i;
        m_callback(m_owner,value,&i);
    }
    else value ^= i;
}

// class TWintProp
//------------------------------------------------------------------------------
TWintProp::TWintProp()
{
    value = 0;
    m_owner = NULL;
    m_callback = NULL;
}

TWintProp::~TWintProp()
{
}

void TWintProp::bindMethod(void *owner, void *AccessFunc)
{
    m_owner = owner;
    m_callback = (TWint (*)(void *,TWintObj&,TWint *)) AccessFunc;
}

TWintProp& TWintProp::operator=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
        m_callback(m_owner,value,&i);
    else value = i;
    return *this;
}

TWintProp::operator TWint() const
{
    if (m_owner != NULL && m_callback != NULL)
        return m_callback(m_owner,(TWintObj&)value,NULL);
    else return value;
}

TWintProp& TWintProp::operator++()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint i = value + 1;
        m_callback(m_owner,value,&i);
    }
    else ++value;
    return *this;
}

TWintProp& TWintProp::operator++(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint i = value + 1;
        m_callback(m_owner,value,&i);
    }
    else value++;
    return *this;
}

TWintProp& TWintProp::operator--()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint i = value - 1;
        m_callback(m_owner,value,&i);
    }
    else --value;
    return *this;
}

TWintProp& TWintProp::operator--(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint i = value - 1;
        m_callback(m_owner,value,&i);
    }
    else value--;
    return *this;
}

void TWintProp::operator*=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value * i;
        m_callback(m_owner,value,&i);
    }
    else value *= i;
}

void TWintProp::operator/=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value / i;
        m_callback(m_owner,value,&i);
    }
    else value /= i;
}

void TWintProp::operator%=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value % i;
        m_callback(m_owner,value,&i);
    }
    else value %= i;
}

void TWintProp::operator+=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value + i;
        m_callback(m_owner,value,&i);
    }
    else value += i;
}

void TWintProp::operator-=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value - i;
        m_callback(m_owner,value,&i);
    }
    else value -= i;
}

void TWintProp::operator<<=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint iValue = value << i;
        m_callback(m_owner,value,&iValue);
    }
    else value <<= i;
}

void TWintProp::operator>>=(TInt i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TWint iValue = value >> i;
        m_callback(m_owner,value,&iValue);
    }
    else value >>= i;
}

void TWintProp::operator&=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value & i;
        m_callback(m_owner,value,&i);
    }
    else value &= i;
}

void TWintProp::operator|=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value | i;
        m_callback(m_owner,value,&i);
    }
    else value |= i;
}

void TWintProp::operator^=(TWint i)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        i = value ^ i;
        m_callback(m_owner,value,&i);
    }
    else value ^= i;
}

// class TFloatProp
//------------------------------------------------------------------------------
TFloatProp::TFloatProp()
{
    value = 0;
    m_owner = NULL;
    m_callback = NULL;
}

TFloatProp::~TFloatProp()
{
}

void TFloatProp::bindMethod(void *owner, void *AccessFunc)
{
    m_owner = owner;
    m_callback = (TDouble (*)(void *,TFloatObj&,TDouble *)) AccessFunc;
}

TFloatProp& TFloatProp::operator=(TDouble f)
{
    if (m_owner != NULL && m_callback != NULL)
        m_callback(m_owner,value,&f);
    else value = f;
    return *this;
}

TFloatProp::operator TDouble() const
{
    if (m_owner != NULL && m_callback != NULL)
        return m_callback(m_owner,(TFloatObj&)value,NULL);
    else return value;
}

TFloatProp& TFloatProp::operator++()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TDouble f = value + 1;
        m_callback(m_owner,value,&f);
    }
    else ++value;
    return *this;
}

TFloatProp& TFloatProp::operator++(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TDouble f = value + 1;
        m_callback(m_owner,value,&f);
    }
    else value++;
    return *this;
}

TFloatProp& TFloatProp::operator--()
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TDouble f = value - 1;
        m_callback(m_owner,value,&f);
    }
    else --value;
    return *this;
}

TFloatProp& TFloatProp::operator--(int)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        TDouble f = value - 1;
        m_callback(m_owner,value,&f);
    }
    else value--;
    return *this;
}

void TFloatProp::operator*=(TDouble f)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        f = value * f;
        m_callback(m_owner,value,&f);
    }
    else value *= f;
}

void TFloatProp::operator/=(TDouble f)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        f = value / f;
        m_callback(m_owner,value,&f);
    }
    else value /= f;
}

void TFloatProp::operator+=(TDouble f)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        f = value + f;
        m_callback(m_owner,value,&f);
    }
    else value += f;
}

void TFloatProp::operator-=(TDouble f)
{
    if (m_owner != NULL && m_callback != NULL)
    {
        f = value - f;
        m_callback(m_owner,value,&f);
    }
    else value -= f;
}

// class TStringProp
//------------------------------------------------------------------------------
TStringProp::TStringProp()
{
    value = CseEmptyStr;
    m_owner = NULL;
    m_callback = NULL;
}

TStringProp::~TStringProp()
{
}

void TStringProp::bindMethod(void *owner, void *AccessFunc)
{
    m_owner = owner;
    m_callback = (const TXchar* (*)(void *,TCharArray&,const TXchar**)) AccessFunc;
}

TStringProp& TStringProp::operator=(const TXchar* s)
{
    if (m_owner != NULL && m_callback != NULL)
        m_callback(m_owner,value,&s);
    else value = s;
    return *this;
}

TStringProp::operator const TXchar*() const
{
    if (m_owner != NULL && m_callback != NULL)
        return m_callback(m_owner,(TCharArray&)value,NULL);
    else return value;
}

TBool operator==(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) == (const TXchar*)y;
}

TBool operator==(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x == y;
}

TBool operator==(const TCharArray& x, const TStringProp& y)
{
    return x == (const TXchar *)y;
}

TBool operator==(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) == y;
}

TBool operator==(const TXchar *x, const TStringProp& y)
{
    return x == TCharArray(y);
}

TBool operator!=(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) != (const TXchar*)y;
}

TBool operator!=(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x != y;
}

TBool operator!=(const TCharArray& x, const TStringProp& y)
{
    return x != (const TXchar *)y;
}

TBool operator!=(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) != y;
}

TBool operator!=(const TXchar *x, const TStringProp& y)
{
    return x != TCharArray(y);
}

TBool operator>(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) > (const TXchar*)y;
}

TBool operator>(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x > y;
}

TBool operator>(const TCharArray& x, const TStringProp& y)
{
    return x > (const TXchar *)y;
}

TBool operator>(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) > y;
}

TBool operator>(const TXchar *x, const TStringProp& y)
{
    return x > TCharArray(y);
}

TBool operator>=(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) >= (const TXchar*)y;
}

TBool operator>=(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x >= y;
}

TBool operator>=(const TCharArray& x, const TStringProp& y)
{
    return x >= (const TXchar *)y;
}

TBool operator>=(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) >= y;
}

TBool operator>=(const TXchar *x, const TStringProp& y)
{
    return x >= TCharArray(y);
}

TBool operator<(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) < (const TXchar*)y;
}

TBool operator<(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x < y;
}

TBool operator<(const TCharArray& x, const TStringProp& y)
{
    return x < (const TXchar *)y;
}

TBool operator<(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) < y;
}

TBool operator<(const TXchar *x, const TStringProp& y)
{
    return x < TCharArray(y);
}

TBool operator<=(const TStringProp& x, const TStringProp& y)
{
    return TCharArray(x) <= (const TXchar*)y;
}

TBool operator<=(const TStringProp& x, const TCharArray& y)
{
    return (const TXchar *)x <= y;
}

TBool operator<=(const TCharArray& x, const TStringProp& y)
{
    return x <= (const TXchar *)y;
}

TBool operator<=(const TStringProp& x, const TXchar *y)
{
    return TCharArray(x) <= y;
}

TBool operator<=(const TXchar *x, const TStringProp& y)
{
    return x <= TCharArray(y);
}
